<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm" style="padding-bottom: 300px!important;">
    <div class="page-title"><div class="page-title-con"><span>编辑款项类型</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>付款明细</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>款项类型</th>
                            <th>付款对象</th>
                            <th>账户名称</th>
                            <th>账号</th>
                            <th>开户行</th>
                            <th>本次付款金额(元)</th>
                            <th>支付方式</th>
                            <th>款项说明</th>
                            <th>本次支付占用进项票金额(元)</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_hou_dayzhi_kuan, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var list = res.data.list;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><div class="zhiqilei zhiqilei'+nums+'" key="'+nums+'"></div></td>';
                        str += '<td><input type="text"  value="'+list[key].fuer+'" listid="'+list[key].id+'" readonly class="layui-input fuer disabled"></td>';
                        str += '<td><input type="text" value="'+list[key].bankzhang+'" readonly class="layui-input bankzhang disabled"></td>';
                        str += '<td><input type="text" value="'+list[key].banknum+'" disabled class="layui-input banknum disabled"></td>';
                        str += '<td><input type="text" value="'+list[key].bankname+'" disabled class="layui-input bankname disabled"></td>';
                        str += '<td><input type="number" value="'+list[key].money+'" disabled class="layui-input money disabled"></td>';
                        str += '<td><input type="text" value="'+list[key].incdaotype_name+'" disabled class="layui-input incdaotype_name disabled"></td>';
                        str += '<td><input type="text" class="layui-input explain disabled" value="'+list[key].explain+'" disabled></td>';
                        str += '<td><input type="text" value="'+list[key].difee+'" readonly class="layui-input difee disabled">';
                        str += '<span class="difeeobj layui-hide">'+list[key].difeeobj+'</span></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                        xmselect_list_dan('zhiqilei'+nums, res.data.zhiqilei, list[key].zhiqilei);
                        update_refresh_row_func()
                    }
                }

                initParseMoney();
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}



            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.fuer').attr('listid') || 0;
                    var zhiqilei = $(this).find('.zhiqilei').find('input').val();

                    var index = i + 1;
                    if(!zhiqilei){
                        throw new Error('第'+index+'行，请选择款项类型');
                    }

                    list.push({
                        id:id,
                        zhiqilei:zhiqilei,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;



            data.field.id = param_id;
            data = parseMoney(data);

            facade.ajax({url: ask_hou_dayzhi_kuan, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success("提交成功!");
                    setTimeout(() => {
                        parent.window.location.reload();
                    }, 1500);
                }
            });
            return false;
        });

    });




    function update_refresh_row_func() {
        render_date();
        render_from();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }



</script>
</body>
</html>
